package com.drojian.demo1.test2;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.drojian.demo.R;

public class ProgressBarActivity extends AppCompatActivity {
    private ProgressBar bar;
    private ProgressBar bar2;
    private Button btn1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.ui2_activity_progress_bar);

        bar = findViewById(R.id.progressBar1);
        bar2 = findViewById(R.id.progressBar2);
        btn1= findViewById(R.id.progressButton1);

        Button back = findViewById(R.id.back);
        back.setOnClickListener(v->finish());
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 创建提醒对话框的建造器
                AlertDialog.Builder builder = new AlertDialog.Builder(ProgressBarActivity.this);
                //设置对话框的标题文本
                builder.setTitle("尊敬的用户");
                //设置对话框的文本内容
                builder.setMessage("刷新频繁");
                //设置对话框的肯定按钮文本及其点击监听器
                builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                // 设置否定按钮文本及其点击监听器
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });

                //显示提醒对话框
                builder.show();

            }
        });

    }
    //进度条的显示与隐藏
    public void appearOnclick(View view) {
        if(bar.getVisibility() == View.GONE){
            bar.setVisibility(View.VISIBLE);
        }else{
            bar.setVisibility(View.GONE);
        }
    }

    public void loadOnclick(View view) {
        int len =  bar2.getProgress();
        len += 10;
        bar2.setProgress(len);

    }
}